<?php

if(!isEmptyArr($_POST) && $_POST['tryLogin'] == 1)
{
  if ($_POST['login'] == __CFG_ADMIN_USERNAME && $_POST['password'] == __CFG_ADMIN_PASSWORD)
  {
    $sID->assign("isAdminLogin", __TRUE);
    $sID->assign("isGlobalAdmin", __TRUE);
    $sID->assign("admin", array('AdmLogin' => $_POST['login'], 'AdmPass' => $_POST['password'], 'AdmGroup' => 'lamer', 'AdmMode' => $mode));
    $sID->assign("Editor", array('Enabled' => __TRUE, 'EnableFileManager' => __TRUE));
    if($sID->fetch("LoginMode") != $_REQUEST['mode'] && !isBlank($sID->fetch("LoginMode")))
    {
      go_to($sID->fetch("LoginRedirect"));
    }
    else
    {      go_to("index.php?mode=".$CONFIG['defaultAdminMode']);
    }
    exit();
  }
  else
  {
    $Result = getRowByFields($_SQL_TABLE['admin_user'], array("login = '".$_POST['login']."'", "password = '".md5($_POST['password'])."'"));
    if($Result['login'] == $_POST['login'] && $Result['active'] == 'y')
    {      $mode = $CONFIG['defaultAdminMode'];
      $sID->assign("isAdminLogin", __TRUE);
      $sID->assign("isGlobalAdmin", __FALSE);
      $sID->assign("admin", array('AdmLogin' => $Result['login'], 'AdmPass' => $Result['password'], 'AdmGroup' => $Result['user_group'], 'AdmMode' => $mode));
      $sID->assign("Editor", array('Enabled' => __TRUE, 'EnableFileManager' => __TRUE));
      if($sID->fetch("LoginMode") != $_REQUEST['mode'] && !isBlank($sID->fetch("LoginMode")))
      {
        go_to($sID->fetch("LoginMode"));
      }
      else
      {
        go_to("index.php?mode=".$CONFIG['defaultAdminMode']);
      }
    }
    elseif($Result['active'] == 'n')
    {	  $tpl->assign("ErrorMsg", $ERRORS['admin'][__ERROR_USER_LOCK_BY_ADMIN]);
    }
    else
    {
      $tpl->assign("ErrorMsg", $ERRORS['admin'][__ERROR_WRONG_LOGIN_OR_PASSWORD]);
    }
  }
}
$tpl->assign("PageTitle", $language['admin']['loginPage']);

$_ADMIN_SMARTY_TEMPLATE = "admin.login.tpl";

?>